home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstvol.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  6KB  |  170 lines

  1. {$X+,B-,V-} {essential compiler directives}
  2.  
  3. program tstvol;
  4.  
  5. { Example for the nwFile unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  6.  
  7. { Tests the following volume related functions in nwFile and nwServ:
  8.  
  9.   ClearObjectVolRestriction
  10.   GetDiskUtilization (nwServ)
  11.   GetObjectVolRestriction
  12.   GetVolumeName
  13.   GetVolumeNumber
  14.   GetVolumeUsage
  15.   IsVolumeRemovable
  16.   SetObjectVolRestriction
  17.  
  18. }
  19.  
  20. uses nwMisc,nwServ,nwFile;
  21.  
  22.  
  23. Var volNbr :byte;
  24.     volName:string;
  25.  
  26.     volUsage   :TvolUsage;
  27.     isremovable:boolean;
  28.  
  29.     MaxAllowedBlocks,
  30.     BlocksInUse:Longint;
  31.  
  32.     VolumeNbr   :byte;
  33.     sequenceNbr :LongInt;
  34.     NbrOfObjects:byte;
  35.     ResultBuffer:TobjVolRestr;
  36.  
  37.     usedDirs,usedFiles,usedBlocks:word;
  38.  
  39.     t:byte;
  40. begin
  41. writeln('Testing GetVolumeNumber');
  42. IF GetVolumeNumber('XXXX',volNbr)
  43.  then writeln('--Err. GetVolumeNuber returned a volumenumber when it should have failed.');
  44. IF GetVolumeNumber('VOL',volNbr)
  45.  then writeln('  VolNbr of ''VOL:'' equals ',volNbr)
  46.  else writeln('  Volume VOL appears not to exist.');
  47. IF GetVolumeNumber('SYS',volNbr)
  48.  then writeln('  VolNbr of SYS: equals ',volNbr)
  49.  else begin
  50.       writeln('Error Using GetVolumeNumber, err#',nwFile.result);
  51.       writeln('Critical error. Test aborted.');
  52.       halt(1);
  53.       end;
  54.  
  55. writeln;
  56. writeln('Testing GetVolumeName');
  57. for volNbr:=0 to 31
  58.  do begin
  59.     IF GetVolumeName(volNbr,volName)
  60.      then writeln('  VolNbr ',volNbr,' is ''',volName,'''')
  61.      else if result<>$98 { no such volume }
  62.           then writeln('--Error testing GetVolumeName, err#',result);
  63.     end;
  64.  
  65. writeln;
  66. writeln('Testing GetVolumeUsage.');
  67. IF GetVolumeNumber('SYS:',volNbr) and GetVolumeUsage(volNbr,VolUsage)
  68.  then with VolUsage
  69.        do begin
  70.           writeln('  Volume Usage Information:');
  71.           writeln('  Total Blocks: ',totalBlocks,' Free: ',freeBlocks);
  72.           writeln('  Total Dir entries: ',totalDirEntries,' Free: ',availDirEntries);
  73.           writeln('  Volumename: ''',volumename,'''');
  74.           writeln('  Blocksize: ',SectorsPerBlock*512,' bytes.');
  75.           end;
  76.  
  77.  
  78. writeln;
  79. writeln('Testing IsVolumeRemovable');
  80. IF IsVolumeRemovable(0,isremovable)
  81.  then writeln('  Removable: ',isremovable)
  82.  else writeln('--IsVolumeRemovable failed.');
  83.  
  84.  
  85. {==================Testing the volume restriction calls====================}
  86.  
  87. GetVolumeNumber('SYS',volNbr);
  88.  
  89. writeln('Getting the volume restrictions for user supervisor on SYS volume..');
  90. IF GetObjectVolRestriction(volNbr,1 {objectId of Supervisor},
  91.                            MaxAllowedBlocks,BlocksInUse)
  92.  then begin
  93.       writeln('  GetObjectVolRestriction:');
  94.       writeln('  Supervisor on volume SYS');
  95.       write('  Restricted to:');
  96.       if MaxAllowedBlocks=$40000000
  97.        then write('(unlimited)')
  98.        else write(MaxAllowedBlocks);
  99.       writeln(' Blocks ,BlocksInUse: ',BlocksInUse);
  100.       end
  101.  else writeln('--Error returned by GetObjectVolRestriction, err#',nwFile.result);
  102.  
  103. writeln;
  104. writeln('Testing GetDiskUtilization (nwServ) for user supervisor');
  105. IF NOT nwServ.GetDiskUtilization(volNbr,1 {supervisor ObjId},usedDirs,usedFiles,usedBlocks)
  106.  then begin
  107.       writeln('--Error returned by nwServ.GetDiskUtilization, err#',nwServ.result);
  108.       if nwServ.result>=$89
  109.        then writeln('--( Object Search/Read rights are necessary.)');
  110.       end
  111.  else begin
  112.       writeln('  dirs in use  :',usedDirs);
  113.       writeln('  files in use :',usedFiles);
  114.       writeln('  blocks in use:',usedBlocks);
  115.       { note that blocksinuse is a word (Max ownership= 262 Mb.)
  116.         GetObjectVolRestriction returns the BlocksInUse value as a LongInt }
  117.       writeln('  (created/owned dirs/files/blocks)');
  118.       end;
  119.  
  120. writeln('Test of SetObjectVolRestriction:');
  121. IF NOT SetObjectVolRestriction(volNbr,$1,BlocksInUse+100)
  122.  then begin
  123.       writeln('--Error returned by setObjectVolRestriction, err#',nwFile.result);
  124.       if nwFile.result=140
  125.        then writeln('--( Supervisor equivalent rights are necessary.)');
  126.       end
  127.  else writeln('--OK, volume restriction set.');
  128.  
  129. IF GetObjectVolRestriction(volNbr,$1 {objectId of Supervisor},
  130.                            MaxAllowedBlocks,BlocksInUse)
  131.  then begin
  132.       if MaxAllowedBlocks=$40000000 { no restriction }
  133.        then writeln('--SetObjectVolRestriction failed.');
  134.       end;
  135.  
  136. writeln;
  137. writeln('Testing ScanVolForRestrictions:');
  138. sequenceNbr:=0;
  139. While ScanVolForRestrictions(volNbr,sequenceNbr,NbrOfObjects,ResultBuffer)
  140.  do begin
  141.     for t:=1 to NbrOfObjects
  142.      do begin
  143.         write('  ObjectId:',HexStr(resultbuffer[t].objId,8));
  144.         writeln(' /Restriction: ',resultBuffer[t].MaxallowedBlocks,' Blocks');
  145.         end;
  146.     end;
  147. IF nwFile.result=$FF { NO MORE DATA, normal iteration end }
  148.  then writeln('--No (more) volume restrictions.')
  149.  else writeln('--Error returned by ScanVolForRestrictions, err#',nwFile.result);
  150.  
  151.  
  152. writeln;
  153. writeln('Clearing SUPERVISOR restrictions using ClearObjectVolRestriction.');
  154. IF NOT ClearObjectVolRestriction(VolNbr,$1)
  155.  then begin
  156.       writeln('--Error calling ClearObjectVolRestriction, err#',nwFile.result);
  157.       if nwFile.result=140
  158.        then writeln('--( Supervisor equivalent rights are necessary.)');
  159.       end;
  160.  
  161.  
  162. IF GetObjectVolRestriction(volNbr,1 {objectId of Supervisor},
  163.                            MaxAllowedBlocks,BlocksInUse)
  164.  then begin
  165.       if MaxAllowedBlocks=$40000000
  166.        then writeln('--OK, user now has no restriction.')
  167.        else writeln('--Error: ClearObjectVolRestriction Failed.');
  168.       end;
  169.  
  170. end.